<template>
  <a-drawer :title="title" :width="width" placement="right" :closable="false" @close="close" :visible="visible">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="用户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="true" v-decorator="['name', validatorRules.name]" placeholder="请输入用户姓名"></a-input>
        </a-form-item>
        <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="true" v-decorator="['identityCard']" placeholder="请输入身份证号"></a-input>
        </a-form-item>
        <!-- <a-form-item label="所属部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            show-search
            placeholder="请选择所属部门"
            v-decorator="['companyId']"
            style="width: 200px"
            @change="handleChange"
          >
            <a-select-option v-for="(item) in companyList" :key="item.value">{{item.label}}</a-select-option>
          </a-select>
        </a-form-item> -->
        <a-form-item label="昵称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="true" v-decorator="['nickname']" placeholder="请输入昵称"></a-input>
        </a-form-item>
        <a-form-item label="手机号码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="true" v-decorator="['mobile']" placeholder="请输入手机号码"></a-input>
        </a-form-item>
        <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="true" v-decorator="['email']" placeholder="请输入邮箱"></a-input>
        </a-form-item>
        <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['gender', validatorRules.gender]" :trigger-change="true" dictCode="DataDictionary,description,sequenceId, dictionaryTypeId =USER_SEX" placeholder="请选择性别"/>
        </a-form-item>
       
      </a-form>
    </a-spin>
    <!-- <a-button type="primary" @click="handleOk" v-if="!disableSubmit">确定</a-button> -->
    <a-button type="primary" @click="handleCancel">关闭</a-button>
  </a-drawer>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import validate from '@/utils/validate'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'

export default {
  name: 'PerTemporaryTaskModal',
  components: {},
  data() {
    return {
      form: this.$form.createForm(this),
      title: '操作',
      width: 800,
      visible: false,
      model: {},
      dateFormat: 'YYYY-MM-DD',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        userLoginId: {
          rules: [
            { required: true, message: '请输入登录账号!', trigger: 'blur' },
            { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' },
          ],
        },
        currentPassword: {
          rules: [
            { required: true, message: '请输入密码!', trigger: 'blur' },
            { min: 6, max: 64, message: '长度不能小于6个字符', trigger: 'blur' },
          ],
        },
        currentPasswordVerify: {
          rules: [
            { required: true, message: '请再次输入密码!', trigger: 'blur' },
            { min: 0, max: 64, message: '长度不能小于6个字符', trigger: 'blur' },
          ],
        },
        firstName: {
          rules: [{ required: true, message: '请输入用户姓名!' }],
        },
      },
      url: {
        add: '/online/user/createSysUser',
        edit: '/online/user/updateSysUser',
      },
      disableSubmit: false,
      companyList: [],
    }
  },
  created() {},
  methods: {
    add() {
      this.edit({})
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(this.model, 'name', 'gender', 'identityCard', 'companyId', 'mobile', 'email', 'birthDate')
        )
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    validateRoleCode(rule, value, callback) {
      if (/[\u4E00-\u9FA5]/g.test(value)) {
        callback('密码不可输入汉字!')
      }
    },
    compareToFirstPassword(rule, value, callback) {
      const form = this.form
      if (value && value !== form.getFieldValue('currentPassword')) {
        callback('两次输入的密码不一样！')
      } else {
        callback()
      }
    },
    handleChange() {},
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.userLoginId) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model, values)
          console.log('表单提交数据', formData)
          httpAction(httpurl, formData, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    popupCallback(row) {
      this.form.setFieldsValue(pick('name', 'gender', 'identityCard', 'companyId', 'mobile', 'email', 'birthDate'))
    },
  },
}
</script>

<style lang="less" scoped>
/** Button按钮间距 */
.ant-btn {
  margin-left: 30px;
  margin-bottom: 30px;
  float: right;
}
.ant-input[disabled] {
  color: rgba(0, 0, 0, 0.65);
  background-color: #fff!important;
  cursor: auto;
  opacity: 1;
}
/deep/ .ant-select-disabled .ant-select-selection {
    background: #fff;
    cursor: auto;
}
</style>
